package com.design.pattern.observer;

import java.util.Observable;
import java.util.Observer;

public class CurrentConditionDisplay2 implements Observer,DisplayElement {

    private Observable observable;
    private float temp;
    private float humidity;
    private float pressure;

    public CurrentConditionDisplay2(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    public void display() {
        System.out.println("CurrentConditionDisplay2 当前温度：" + temp + "F; 湿度为：" + humidity + "%; 气压为:" + pressure);
    }

    public void update(Observable obs, Object arg) {
        if(obs instanceof WeatherData2){
            this.temp = ((WeatherData2) obs).getTemp();
            this.humidity = ((WeatherData2) obs).getHumidity();
            this.pressure = ((WeatherData2) obs).getPressure();
        }
        display();
    }
}